#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <string.h>
#include <log.h>
#include <timer.h>

#include <scu.h>

typedef struct mystruct_s
{
  int id;
  char string[256];
} mystruct_t;

int MAIN(void)
{
  scu_list_t l;
  scu_listitem_t *item;
  mystruct_t *s;
  int i;
  
  l = scuListCreate(sizeof(mystruct_t));
  
  for (i=0; i < 100; i++)
    sprintf(((mystruct_t*)scuListAddItem(&l))->string, "Item %d", i);

  printf("List has %d items\n", scuListGetLength(&l));
  
  printf("Item %d has text '%s'\n", 45, ((mystruct_t*)scuListGetItem(&l, 45))->string);
  printf("Item %d has text '%s'\n", 12, ((mystruct_t*)scuListGetItem(&l, 12))->string);
  printf("Item %d has text '%s'\n", 56, ((mystruct_t*)scuListGetItem(&l, 56))->string);

  printf("Item with text '%s' is %d\n", "Item 11",
         ((mystruct_t*)scuListFindItem(&l, 4, SCU_VAR_STRING, "Item 11"))->id);

  scuListRemoveItem(&l, 28);
  
  if (!scuListGetItem(&l, 28))
    printf("Listitem %d successfully removed\n", 28);
  else
    printf("Failed to remove listitem %d\n", 28);

  printf("List has %d items\n", scuListGetLength(&l));

  for (i=0; i < 100; i+= 2)
    scuListRemoveItem(&l, i);

  item = NULL;
  while ((s = ((mystruct_t*)scuListEnumerateItems(&l, &item))))
    printf("Enumerated item %d with text '%s'\n", s->id, s->string);

  scuListFree(&l);
  
  printf("List has %d items\n", scuListGetLength(&l));
  
  return 0;
}
